//
// Created by 11510 on 2024/6/21.
//
#include <iostream>
#include <string>

using namespace std;


class SafeFile {
private:
    FILE *_fp;

public:
    SafeFile(FILE *fp) : _fp(fp) {}

    ~SafeFile() {
        if (_fp) {
            fclose(_fp);
            _fp = nullptr;
        }
    }

    /**
     * 提供访问资源的方法
     */
    void write(const string &msg) {
        fwrite(msg.c_str(), 1, msg.size(), _fp);
    }
};


void test0() {
    string msg("goodbye world");
    SafeFile safeFile(fopen("../word.txt", "a+"));

    safeFile.write(msg);



}


int main() {
    test0();
    return 0;
}